<template>
  <div class="p-2">
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form ref="formRef" @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item name="issueDate">
              <template #label><span title="开票月份">开票月份</span></template>
              <a-date-picker picker="month" value-format="YYYY-MM" placeholder="请选择月份" v-model:value="queryParam.issueDate" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="invoiceStatus">
              <template #label><span title="发票状态">发票状态</span></template>
              <j-input placeholder="请输入发票状态" v-model:value="queryParam.invoiceStatus" allow-clear ></j-input>
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="buyerIdentificationNumber">
              <template #label><span title="购方税号">购方税号</span></template>
              <j-input placeholder="请输入购方税号" v-model:value="queryParam.buyerIdentificationNumber" allow-clear ></j-input>
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="buyerName">
              <template #label><span title="购买方名称">购买方名称</span></template>
              <j-input placeholder="请输入购买方名称" v-model:value="queryParam.buyerName" allow-clear ></j-input>
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="status">
              <template #label><span title="是否已报销">是否已报销</span></template>
              <j-dict-select-tag placeholder="是否已报销" v-model:value="queryParam.status" dictCode="yn" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>
<!--        <a-button type="primary" v-auth="'finance:f_invoice_management:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>-->
        <!-- 高级查询 -->
        <super-query :config="superQueryConfig" @search="handleSuperQuery" />
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts" name="finance-statisticsManagement" setup>
  import { ref, reactive } from 'vue';
  import dayjs from 'dayjs';
  import { BasicTable, useTable } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns, superQuerySchema } from './statisticsManagement.data';
  import { list, getExportUrl } from './statisticsManagement.api';
  import JInput from "@/components/Form/src/jeecg/components/JInput.vue";
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import { cloneDeep } from "lodash-es";

  const formRef = ref();
  const queryParam = reactive<any>({
    issueDate: dayjs().format('YYYY-MM')
  });
  const toggleSearchStatus = ref<boolean>(false);
  
  //注册table数据
  const { prefixCls, tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '发票统计',
      api: list,
      columns,
      canResize: false,
      useSearchForm: false,
      beforeFetch: async (params) => {
        return Object.assign(params, cloneDeep(queryParam));
      },
    },
    exportConfig: {
      name: "发票统计",
      url: getExportUrl,
      params: queryParam,
    },
  });
  
  const [registerTable, { reload }] = tableContext;
  
  const labelCol = reactive({
    xs: 24,
    sm: 4,
    xl: 6,
    xxl: 4
  });
  
  const wrapperCol = reactive({
    xs: 24,
    sm: 20,
  });

  // 高级查询配置
  const superQueryConfig = reactive(superQuerySchema);

  /**
   * 高级查询事件
   */
  function handleSuperQuery(params) {
    Object.keys(params).map((k) => {
      queryParam[k] = params[k];
    });
    reload();
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }
  
  /**
   * 重置
   */
  function searchReset() {
    formRef.value.resetFields();
    //刷新数据
    reload();
  }
  
  // 无范围查询转换，直接使用表单参数
</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    padding: 0;
    .table-page-search-submitButtons {
      display: block;
      margin-bottom: 24px;
      white-space: nowrap;
    }
    .query-group-cust{
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
    .ant-form-item:not(.ant-form-item-with-help){
      margin-bottom: 16px;
      height: 32px;
    }
    :deep(.ant-picker),:deep(.ant-input-number){
      width: 100%;
    }
  }
</style>
